﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace BrightIdeasSoftware
{
    public partial class DataGridViewBG : DataGridView
    {
        Image image;

        public DataGridViewBG()
        {
            InitializeComponent();
        }

        public DataGridViewBG(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        public override Image BackgroundImage
        {
            get
            {
                return this.image;
            }
            set
            {
                this.image = value;

            }
        }

        protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
        {
            base.PaintBackground(graphics, clipBounds, gridBounds);

            if (this.BackgroundImage == null)
            {
                this.BackgroundImage = global::BrightIdeasSoftware.Properties.Resources.Background2;
            }

            Rectangle rectSource = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
            Rectangle rectDest = new Rectangle(0, 0, rectSource.Width, rectSource.Height);

            Bitmap b = new Bitmap(Parent.ClientRectangle.Width, Parent.ClientRectangle.Height);
            Graphics.FromImage(b).DrawImage(this.BackgroundImage, Parent.ClientRectangle);


            graphics.DrawImage(b, rectDest, rectSource, GraphicsUnit.Pixel);            

            SetCellsTransparent();
        }

        public void SetCellsTransparent()
        {

            //this.EnableHeadersVisualStyles = true;
            //this.ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent;
            //this.RowHeadersDefaultCellStyle.BackColor = Color.Transparent;


            foreach (DataGridViewColumn col in this.Columns)
            {
                col.DefaultCellStyle.BackColor = Color.Transparent;
                //col.DefaultCellStyle.SelectionBackColor = Color.Transparent;
            }
        }
    }
}
